<?php
$loader->requireOnce('includes/inPatientCore/InPatientCoreErrorCode.class.php');
$loader->requireOnce('includes/inPatientCore/InPatientCoreException.class.php');
$loader->requireOnce('ordo/InPatient.class.php');
$loader->requireOnce('ordo/EmployeeType.class.php');
$loader->requireOnce('ordo/Service.class.php');



/**
 * InPatientSurgery Processor.
 * @package core.includes.inPatientCore
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class InPatientSEBase {
	protected $controller;

	private $logger ;


	/**
	 *
	 * @param $controller controller for build ui
	 */
	function __construct($controller) {
		$this->logger = LoggerManager::getLogger('core.inPatientCore.InPatientSEBase');
		$this->controller = $controller;

	}
	
	public function deleteService($ticketId, $surgeryId) {
		
		$participant = Celini::newOrdo('SurgeryParticipant');
        $participant->deleteParticipants($surgeryId);
        
        $surgeryObj = Celini::newOrdo('Surgery');
        $surgeryObj->deleteSurgery($surgeryId);
        $itemType = Utils::getEnumKey(EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE,
        EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE_SURGERY);
        $inTicketItemObj = Celini::newOrdo('InTicketItem');
        $inTicketItemObj->deleteItem($surgeryId, $itemType);
        
        
	}
	
	
	public function addService($ticketId, $surgeryServiceId, $surgeryDate, $doctors) {
		$emr = Celini::newORDO("InPatientEmr");
        $emrInfo =  $emr->getEmrInfo($ticketId);
        
		$surgeryObj = Celini::newOrdo('Surgery');
		$surgeryObj->setData($emrInfo['in_patient_emr_id'], $surgeryDate, '', '',
        '', '', $surgeryServiceId, '');
		$surgeryObj->persist();
		$surgeryId = $surgeryObj->get_id();
		$serviceObj = Celini::newOrdo('Service');
		$prices = $serviceObj->getPrices($ticketId, $surgeryServiceId, EnumerationConstant::SER_INS_ITEM_TYPE_PTTT);
		foreach ($doctors as $doctor) {
			$participant = Celini::newOrdo('SurgeryParticipant');
            $participant->setData($surgeryId, $doctor['id'], $doctor['employeeType']);
            $participant->persist();
		}		
		$itemType = Utils::getEnumKey(EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE,
		EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE_SURGERY);
		$inTicketItemObj = Celini::newOrdo('InTicketItem');
		$inTicketItemObj->setData($surgeryId, $itemType, 0,$prices['price'], $prices['insurance_price'], $prices['patient_price'], $ticketId, null);
        $inTicketItemObj->persist();
		
	}
	
	public function getPatientServiceList($patientId) {
        $surgeryObj     =   Celini::newORDO("Surgery");
        $serviceList    =   $surgeryObj->getSurgeryInfoByPatient($patientId);
        $this->controller->assign('serviceList', $serviceList);
        $this->controller->assign('index', 1);
        $html           =   $this->controller->view->render('service_list_cashier.html');
        return $html;
    }
	
	
}
?>